home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / LISTMANA / __TESTER / NORMALLI.C < prev    next >
Text File  |  1989-06-25  |  9KB  |  386 lines

  1. /****                                                                    */
  2. /****    List Testing Code version 1.0 (beta)                            */
  3. /****                                                                    */
  4. /****    All portions of this source code are the property of Jack        */
  5. /****    Herrington.  I, Jack Herrington, give you permission to use        */
  6. /****    use or alter the code in any way that pleases you.  You must    */
  7. /****    however return by whatever means avaliable any improvements        */
  8. /****    you believe significant to Jack Herrington, accepting that        */
  9. /****    these improvements might be contained in later releases of        */
  10. /****    the code. I also grant you permission to remove this header        */
  11. /****    from any file you are WORKING on, as long as you put it back    */
  12. /****    when you're stopped WORKING on it.                                */
  13. /****                                                                    */
  14. /****    Jack Herrington: University Of Miami, Biomedical Computing        */
  15. /****                     1600 N.W. 10th Ave. (R-53)                        */
  16. /****                     (305) 547-6538                                    */
  17. /****                                                                    */
  18.  
  19. /****/
  20. /**** Normal List Handler */
  21. /****/
  22.  
  23. #include "ListManager.h"
  24. #include "Tester.h"
  25. #include "NormalList.h"
  26.  
  27. /****/
  28. /**** Normal List main dispersion routine */
  29. /****/
  30.  
  31. void NormalListHandler(mess,data)
  32. int mess;
  33. unsigned char *data;
  34. {
  35.     switch(mess)
  36.     {
  37.     case MESS_NEW: NormalListHandlerNew(); break;
  38.     case MESS_HIT: NormalListHandlerHit((int *)data); break;
  39.     case MESS_CLOSE: NormalListHandlerClose(); break;
  40.     case MESS_ACTIVATE: NormalListHandlerActivate(1); break;
  41.     case MESS_DEACTIVATE: NormalListHandlerActivate(0); break;
  42.     case MESS_KEY: NormalListHandlerKey((char)*data); break;
  43.     }
  44. }
  45.  
  46. /****/
  47. /**** Respond to a new message */
  48. /****/
  49.  
  50. void NormalListHandlerNew()
  51. {
  52.     NormalWindowInfo *nwi;
  53.  
  54.         /**** Create the dialog */
  55.  
  56.     if ( TesterDialogNew(1000,CurHandler) == (-1) ) return;
  57.     SetPort(Windows[CurWindow].window);
  58.  
  59.         /**** Allocate the window record */
  60.  
  61.     TesterAllocateWindowData((long)sizeof(NormalWindowInfo));
  62.     TesterLockWindowInfo();
  63.     nwi = (NormalWindowInfo *)TesterGetWindowInfo();
  64.  
  65.         /**** Setup the window */
  66.  
  67.     NormalListHandlerSetupList(nwi);
  68.  
  69.         /**** Unlock the window information and leave */
  70.  
  71.     TesterUnLockWindowInfo();
  72. }
  73.  
  74. /****/
  75. /**** Setup the list */
  76. /****/
  77.  
  78. void NormalListHandlerSetupList(nwi)
  79. NormalWindowInfo *nwi;
  80. {
  81.     Handle item;
  82.     Point cellSize,cell;
  83.     Rect box,dBox;
  84.     char charTmp[255];
  85.     int type,x,y;
  86.  
  87.         /**** Get the box for the list */
  88.  
  89.     GetDItem(Windows[CurWindow].window,ListBox,&type,&item,&box);
  90.     SetDItem(Windows[CurWindow].window,ListBox,type,
  91.         NormalListHandlerUpdate,&box);
  92.  
  93.         /**** Create the data bounds */
  94.  
  95.     dBox.left = 0; dBox.right = MAX_X;
  96.     dBox.top = 0; dBox.bottom = MAX_Y;
  97.     cellSize.h = 80; cellSize.v = 12;
  98.  
  99.         /**** Create the list */
  100.  
  101.     nwi->nlh = ListNew(&box,&dBox,cellSize,0,
  102.         Windows[CurWindow].window,0,0,1,1);
  103.  
  104.         /**** Setup framing parameters */
  105.  
  106.     nwi->frameOff = 20;
  107.     ListSetFrameWidth(nwi->frameOff*2,nwi->frameOff,nwi->nlh);
  108.     ListSetFrameDrawer(NormalListHandlerDrawFrame,nwi->nlh);
  109.  
  110.         /**** Setup global cell definitions */
  111.  
  112.     ListSetGlobalBox((ListBottom|ListRight|ListGray),nwi->nlh);
  113.     ListSetGlobalFont(times,12,0,nwi->nlh);
  114.     ListSetScrollMethod(incMethod,nwi->nlh);
  115.  
  116.         /**** Redo the row and column widths */
  117.  
  118.     for(y=0;y<MAX_Y;y++)ListSetRowWidth(y,15+(y*2),nwi->nlh);
  119.     for(y=0;y<MAX_X;y++)ListSetColumnWidth(y,80+(y*5),nwi->nlh);
  120.  
  121.         /**** Set the bottom and right addative */
  122.  
  123.     ListSetAddative(20,20,nwi->nlh);
  124.  
  125.         /**** Set the cells */
  126.  
  127.     for(y=0;y<MAX_Y;y++)
  128.     {
  129.         for(x=0;x<MAX_X;x++)
  130.         {
  131.             (void)sprintf(charTmp,"%d - %d",x+1,y+1);
  132.             cell.h = x;
  133.             cell.v = y;
  134.     
  135. #ifdef UseTextBox
  136.             ListSetHandler(TextBoxHandler,cell,nwi->nlh);
  137. #else
  138.             (void)CtoPstr(charTmp);
  139. #endif
  140.  
  141.             ListSetCell((unsigned char *)charTmp,strlen(charTmp),cell,nwi->nlh);
  142.         }
  143.     }
  144.  
  145.         /**** Setup the flags */
  146.  
  147.     ListSetEhancedFlags((NoAutoEditingSize),nwi->nlh);
  148.     ListDoDraw(TRUE,nwi->nlh);
  149.  
  150.         /**** Setup the sizeing area */
  151.  
  152.     nwi->sizeArea.top =  15;
  153.     nwi->sizeArea.bottom = 100;
  154.     nwi->sizeArea.left = 30;
  155.     nwi->sizeArea.right = 150;
  156.  
  157.         /**** Hilite the buttons correctly */
  158.     
  159.     NormalListHandlerHilite(nwi);
  160. }
  161.  
  162. /****/
  163. /**** Draw the list */
  164. /****/
  165.  
  166. pascal void NormalListHandlerUpdate(Window,ItemNumber)
  167. WindowPtr Window;
  168. int ItemNumber;
  169. {
  170.     NormalWindowInfo *nwi;
  171.  
  172.         /**** Lock the window information and update */
  173.  
  174.     TesterLockWindowInfoWindow(Window);
  175.     nwi = (NormalWindowInfo *)TesterGetWindowInfoIndirect(Window);
  176.         ListUpdateWhole(nwi->nlh);
  177.     TesterUnLockWindowInfoWindow(Window);
  178. }
  179.  
  180. /****/
  181. /**** Send a key to the list */
  182. /****/
  183.  
  184. void NormalListHandlerKey(key)
  185. char key;
  186. {
  187.     NormalWindowInfo *nwi;
  188.  
  189.         /**** Lock the window information and update */
  190.  
  191.     TesterLockWindowInfo();
  192.     nwi = (NormalWindowInfo *)TesterGetWindowInfo();
  193.         ListEditKey(key,nwi->nlh);
  194.     TesterUnLockWindowInfo();
  195. }
  196.  
  197. /****/
  198. /**** Hit in the window */
  199. /****/
  200.  
  201. void NormalListHandlerHit(hit)
  202. int *hit;
  203. {
  204.     NormalWindowInfo *nwi;
  205.     Point cell,lpt;
  206.     Rect sizeArea;
  207.     int part;
  208.  
  209.         /**** Lock the window information */
  210.  
  211.     TesterLockWindowInfo();
  212.     nwi = (NormalWindowInfo *)TesterGetWindowInfo();
  213.     SetPort(Windows[CurWindow].window);
  214.  
  215.         /**** Disperse according to dialog hit */
  216.  
  217.     if ( *hit == ListBox )
  218.     {
  219.         GetMouse(&lpt);
  220.         part = ListPart(lpt,&cell,nwi->nlh);
  221.         switch(part)
  222.         {
  223.         case inTextEditCell:
  224.             ListEditClick(lpt,(Boolean)0,nwi->nlh);
  225.             break;
  226.         case inHorizSizer:
  227.         case inVertSizer:
  228.             ListCellSizer(nwi->sizeArea,part,cell,nwi->nlh);
  229.             break;
  230.         case inHorizScroll:
  231.         case inVertScroll:
  232.          case inCell:
  233.             if ( ListCickEnhanced(lpt,0,nwi->nlh,ListSingleDrag) == 1 )
  234.             {
  235.                 ListEditStart(ListLastClick(nwi->nlh),nwi->nlh);
  236.             }
  237.             break;
  238.          }
  239.     
  240.         if ( part == inCell ) NormalListHandlerHilite(nwi);
  241.     }
  242.     else if ( *hit == AddColumn )
  243.     {
  244.         cell.h = cell.v = 0;
  245.         ListGetSelect(TRUE,&cell,nwi->nlh);
  246.         ListAddColumn(1,cell.h,nwi->nlh);
  247.         NormalListHandlerHilite(nwi);
  248.     }
  249.     else if ( *hit == DelColumn )
  250.     {
  251.         cell.h = cell.v = 0;
  252.         ListGetSelect(TRUE,&cell,nwi->nlh);
  253.         ListCleanList(nwi->nlh);
  254.         ListDelColumn(1,cell.h,nwi->nlh);
  255.         NormalListHandlerHilite(nwi);
  256.     }
  257.     else if ( *hit == AddRow )
  258.     {
  259.         cell.h = cell.v = 0;
  260.         ListGetSelect(TRUE,&cell,nwi->nlh);
  261.         ListAddRow(1,cell.v,nwi->nlh);
  262.         NormalListHandlerHilite(nwi);
  263.     }
  264.     else if ( *hit == DelRow )
  265.     {
  266.         cell.h = cell.v = 0;
  267.         ListGetSelect(TRUE,&cell,nwi->nlh);
  268.         ListCleanList(nwi->nlh);
  269.         ListDelRow(1,cell.v,nwi->nlh);
  270.         NormalListHandlerHilite(nwi);
  271.     }
  272.     else if ( *hit == Frame )
  273.     {
  274.         if ( nwi->frameOff == 20 ) nwi->frameOff = 0;
  275.         else nwi->frameOff = 20;
  276.         ListSetFrameWidth(nwi->frameOff*2,nwi->frameOff,nwi->nlh);
  277.     }
  278.     else if ( *hit == CleanList )
  279.     {
  280.         ListCleanList(nwi->nlh);
  281.         NormalListHandlerHilite(nwi);
  282.     }
  283.     else if ( *hit == CellSizeButton )
  284.     {
  285.         cell.h = 80;
  286.         cell.v = 15;
  287.         ListCellSize(cell,nwi->nlh);
  288.     }
  289.     else if ( *hit == AutoScrollButton ) ListAutoScroll(nwi->nlh);
  290.  
  291.         /**** Unlock the window information */
  292.  
  293.     TesterUnLockWindowInfo();
  294. }
  295.  
  296. /****/
  297. /**** Change the hiliting on the buttons */
  298. /****/
  299.  
  300. void NormalListHandlerHilite(nwi)
  301. NormalWindowInfo *nwi;
  302. {
  303.     Handle item;
  304.     Point cell;
  305.     Rect box;
  306.     int type,stat;
  307.  
  308.         /**** Find if there is an active cell */
  309.  
  310.     cell.h = cell.v = 0;
  311.     if ( ListGetSelect(TRUE,&cell,nwi->nlh) == TRUE ) stat = 0;
  312.     else stat = 255;
  313.  
  314.         /**** Hilite the buttons */
  315.  
  316.     GetDItem(Windows[CurWindow].window,AddColumn,&type,&item,&box);
  317.         HiliteControl((ControlHandle)item,stat);
  318.     GetDItem(Windows[CurWindow].window,DelColumn,&type,&item,&box);
  319.         HiliteControl((ControlHandle)item,stat);
  320.     GetDItem(Windows[CurWindow].window,AddRow,&type,&item,&box);
  321.         HiliteControl((ControlHandle)item,stat);
  322.     GetDItem(Windows[CurWindow].window,DelRow,&type,&item,&box);
  323.         HiliteControl((ControlHandle)item,stat);
  324. }
  325.  
  326. /****/
  327. /**** Draw the frame title */
  328. /****/
  329.  
  330. void NormalListHandlerDrawFrame(message,visBox,cell)
  331. int message;
  332. Rect *visBox;
  333. int cell;
  334. {
  335.     char charTmp[255];
  336.     int half,width;
  337.  
  338.         /**** Draw the message into the frame */
  339.  
  340.     if ( message == VertCell )
  341.     {
  342.         MoveTo(visBox->left+2,visBox->bottom-2);
  343.  
  344.         NumToString((long)cell+1,charTmp);
  345.         DrawString(charTmp);
  346.         DrawChar('.');
  347.     }
  348.     else if ( cell < MAX_X )
  349.     {
  350.         width = StringWidth(Titles[cell]) / 2;
  351.         half = visBox->left + ( ( visBox->right - visBox->left ) / 2 );
  352.         MoveTo(half-width,visBox->bottom-2);
  353.         DrawString(Titles[cell]);
  354.     }
  355. }
  356.  
  357. /****/
  358. /**** Activate or DeActivate the list */
  359. /****/
  360.  
  361. void NormalListHandlerActivate(act)
  362. int act;
  363. {
  364.     NormalWindowInfo *nwi;
  365.  
  366.     TesterLockWindowInfo();
  367.     nwi = (NormalWindowInfo *)TesterGetWindowInfo();
  368.         ListActivate(act,nwi->nlh);
  369.     TesterUnLockWindowInfo();
  370. }
  371.  
  372. /****/
  373. /**** Close up the window */
  374. /****/
  375.  
  376. void NormalListHandlerClose()
  377. {
  378.     NormalWindowInfo *nwi;
  379.  
  380.     TesterLockWindowInfo();
  381.     nwi = (NormalWindowInfo *)TesterGetWindowInfo();
  382.         ListDispose(nwi->nlh);
  383.     TesterUnLockWindowInfo();
  384.  
  385.     TesterKillWindow(CurWindow);
  386. }